class CreateSections < ActiveRecord::Migration
  def self.up
    create_table :sections do |t|
      # A number that has physical meaning
      # e.g. sura number, bab number
      t.integer :section_no

      # Type of this section (for STI)
      # e.g. Ketab, Bab, Sura
      t.string :type

      # The collection in which this section is located
      t.integer :collection_id

      # Title of this section
      t.string :title, :limit=>4096

      # References parent section (self loop)
      # For acts as nested set
      t.integer :parent_id
      t.integer :lft
      t.integer :rgt
      
      # A description for this section
      # This may be an overview description about a Ketab or Sura
      t.text :description, :limit=>1.megabyte
      
      t.timestamps
    end
    
    # Add indices for faster joining of tables
    add_index :sections, :collection_id
    add_index :sections, :parent_id
  end

  def self.down
    drop_table :sections
  end
end
